<%@page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>
<!-- jqgrid-->
<link
	href="${basePath}/css/plugins/jqgriddemo/css/ui.jqgrid-bootstrap.min.css"
	rel="stylesheet" />
<!doctype html>
<html>
<head>
<style type="text/css">
* {
	margin: 0px;
	padding: 0px;
	font-size: 12px;
}
</style>
</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight creditbody">
		<div class="iboxtitle">
			<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;系统管理&gt;基础信息管理&gt;系统参数维护</span>
			<a href="javascript:void(0)"></a>
		</div>
		<div class="ibox-content">
			<button type="button" class="btn dpbtn_green" onclick="add();">新增</button>
		</div>
		<div class="ibox-content">
			<div role="form" class="form-inline">
				<div class="form-group">
					<label for="loginName" class="sr-only">用户名</label> <input
						type="text" placeholder="参数名称" id="name_param" name="name_param"
						class="form-control">
				</div>
				<button class="zhixcx" type="button" onclick="query();">执行查询</button>
			</div>
		</div>
		<div class="ibox-content">
			<div class="jqGrid_wrapper">
				<table id="table_list_1"></table>
				<div id="pager_list_1"></div>
			</div>
		</div>

		<form class="form-horizontal m-t" id="commentForm">
			<div class="ibox-content" id="hiddenstyle" style="display: none;">
				<div class="form-group">
					<label class="col-sm-3 control-label">参数名称：</label>
					<div class="col-sm-8">
						<input id="nameParam" name="nameParam" minlength="1"
							maxlength="64" type="text" class="form-control" required=""
							aria-required="true" placeholder="参数名称(必填)">
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-3 control-label">参数代码：</label>
					<div class="col-sm-8">
						<input id="code_param" name="code_param" minlength="1"
							maxlength="128" type="text" class="form-control" required=""
							aria-required="true" placeholder="参数代码(必填)">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">参数值：</label>
					<div class="col-sm-8">
						<input id="value_param" name="value_param" minlength="1"
							maxlength="128" type="text" class="form-control" required=""
							aria-required="true" placeholder="参数值(必填)">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">备注：</label>
					<div class="col-sm-8">
						<textarea id="remarks" name="remarks" cols="20" rows="2"
							type="text" class="textarea-control" aria-required="true"
							placeholder="请输入备注" aria-invalid="false"></textarea>
					</div>
				</div>
				<table cellpadding="0" cellspacing="0" border="0"
					bordercolor="#3B95C8" width="100%">
					<tr>
						<td width="100%" align="center">
							<div class="ibox-content">
								<button type="button" class="btn dpbtn_green" onclick="save();">确定</button>
								&nbsp;
								<button type="reset" class="btn dpbtn_red">重置</button>
							</div>
						</td>
					</tr>
				</table>
			</div>
		</form>

		<form class="form-horizontal m-t" id="commentFormb">
			<div class="ibox-content" id="hiddenstyleb" style="display: none;">
				<div class="form-group">
					<label class="col-sm-3 control-label">参数名称：</label>
					<div class="col-sm-8">
						<input id="id" type="hidden" /> <input id="nameParamb"
							name="nameParam" minlength="1" maxlength="64" type="text"
							class="form-control" required="" aria-required="true"
							placeholder="参数名称(必填)">
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-3 control-label">参数代码：</label>
					<div class="col-sm-8">
						<input id="code_paramb" readonly="readonly" name="code_param"
							minlength="1" maxlength="128" type="text" class="form-control"
							required="" aria-required="true" placeholder="参数代码(必填)">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">参数值：</label>
					<div class="col-sm-8">
						<input id="value_paramb" name="value_param" minlength="1"
							maxlength="128" type="text" class="form-control" required=""
							aria-required="true" placeholder="参数值(必填)">
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-3 control-label">备注：</label>
					<div class="col-sm-8">
						<textarea id="remarksb" name="remarks" cols="20" rows="2"
							type="text" class="textarea-control" aria-required="true"
							placeholder="请输入备注" aria-invalid="false"></textarea>
					</div>
				</div>
				<table cellpadding="0" cellspacing="0" border="0"
					bordercolor="#3B95C8" width="100%">
					<tr>
						<td width="100%" align="center">
							<div class="ibox-content">
								<button type="button" class="btn dpbtn_green"
									onclick="codeUpdate();">确定</button>
								&nbsp;
								<button type="reset" class="btn dpbtn_red">重置</button>
							</div>
						</td>
					</tr>
				</table>
			</div>
		</form>
	</div>

	<!-- public quote -->
	<%@include file="/jsp/comm_js_include.jsp"%>

	<!-- jqGrid -->
	<script type="text/javascript" charset="utf-8"
		src="${basePath}/js/plugins/jqgriddemo/js/jquery.jqGrid.min.js"></script>
	<script type="text/javascript" charset="utf-8"
		src="${basePath}/js/plugins/jqgriddemo/js/grid.locale-cn.min.js"></script>

	<!-- custom js -->
	<%@include
		file="/js/common-dpqc/dpqc-validate/comm_validate_include.jsp"%>

	<!--
    	作者：zhangpp
    	时间：2017-04-06
    	描述：js
    -->
	<script type="text/javascript">
		
	    var winWidth = $(window).width();
		var winHeight = $(window).height();
	
    	$(function(){
    		getInitData();
    	});
    	
    	
    	var getInitData = function()
    	{
    	   winWidth = $(window).width();
       	   winHeight = document.body.offsetHeight - 400;
    	   var win = winWidth / 7 - 20;
   	 	   $.jgrid.defaults.styleUI = 'Bootstrap';
 		  jQuery("#table_list_1").jqGrid
 		  ({
 			url:'${basePath}/BaseSysParamsController/list',
 	        datatype : "json",
 	        colNames : ['主键', '参数名称', '参数代码' ,'参数值'],
 	        colModel : [  
 						 {name: 'replaceId', index: '', hidden:true},
 	                     {name: 'nameParam',index: '',width: win,align: "center"},
 	               		 {name: 'codeParam',index: '',width:win,align: "center"},
 	                     {name: 'valueParam',index: '',width:win,align: "center"}
 	                   ],
               mtype : "post",
               height: winHeight,
               autowidth: true,
               shrinkToFit: true,
               width:winWidth,  
               rowNum: 15,
               sortorder : "desc",
               sortname : 'created',
               rowList: [15, 30, 45],
               viewrecords: true,
               pager: "#pager_list_1",
               hidegrid: false,
               multiselect : true,
               altRows:true,
               altclass:'someClass',
               ondblClickRow:function(rowId,v,e)
               {
             	  var rowData = $("#table_list_1").jqGrid("getRowData", rowId);
             	  var id = rowData.replaceId;
             	  document.getElementById('id').value = id;
             	  changelayer=layer.open({
          			  type: 1,
          			  area: ['480px', '50%'], //宽高
        			  content: $('#hiddenstyleb'),
          			});
             	  
             	  $.dpAjax({
	         	   		url:'${basePath}/BaseSysParamsController/getById',
	         	   		data:{
	         	   			"id":id
	         	   		},
	         			success: function(datas)
	         			{
	         		 	  if(datas.flag == "100100")
	         		 	  {
	         		 		  var d = datas.result;
	         		 		  $('#nameParamb').val(d.nameParam);
	         		 		  $('#value_paramb').val(d.valueParam);
	         		 		  $('#code_paramb').val(d.codeParam);
	         		 		  $('#remarksb').val(d.remarks);
	         				  return;
	         			  }
	         			  if(datas.flag == "100200"){
	         				  alert(JSON.stringify(datas));
	         	              return;
	         	          }
	         			  layer.msg(datas.message, {icon: 2});
	         			}
         	   		});
               },
               jsonReader : {
             	  root:"result.rows",
             	  page: "result.page",
             	  total: "result.total",
             	  records: "result.records",
             	  repeatitems: false,
             	  id: "replaceId" 
               },
               loadComplete:function(datas){
             	  if (datas.flag == "100100") {
                       layer.msg("查询成功!", {icon: 6, time: 1000});
                       return;
                   }
             	  if(datas.flag == '100802') {
     				  top.location.href = thisLoginUrl;
     				  return;
     			  }

             	  layer.msg(datas.message, {icon: 2});
               }

 	      });
    	}
    	
    	window.onresize = function()
 	    {
 	    	$("#table_list_1").setGridWidth($(window).width()-80);
 	    }
    	
    	var query = function()
	    {
	    	var postData = $("#table_list_1").jqGrid("getGridParam", "postData");
	    	var name_param = document.getElementById('name_param').value || '';
	    	$.extend(postData, { nameParam : name_param.trim() });
	    	refresh();
	    }
    	
    	var refresh = function()
	    {
	    	$("#table_list_1").jqGrid("setGridParam", { search: true }).trigger("reloadGrid", [{ page: 1}]);
	    }
    	
    	var addlayer;
    	var add = function()
    	{
    		addlayer=layer.open({
   			  type: 1,
   			  area: ['480px', '50%'], //宽高
   			  content: $('#hiddenstyle')
   			});	
    	}
    	
    	var save = function()
    	{
    	   var name_param = $('#nameParam').val();
    	   var value_param = $('#value_param').val();
    	   var code_param = $('#code_param').val();
    	   var remarks = $('#remarks').val();
    	   $.dpAjax({
    	   		url:'${basePath}/SystemController/getSystemParamsCount',
    	   		data:{
    	   			"codeParam":code_param
    	   		},
    			success: function(datas)
    			{
    		 	  if(datas.flag == "100100")
    		 	  {
    		 		  var count = datas.result;
    		 		  if(count && null != count)
    		 		  {
    		 			 layer.msg("编码重复！", {icon: 2});
    		 			 return;
    		 		  }
    		 		  saveCode();
    				  return;
    			  }
    			  if(datas.flag == "100200"){
    				  alert(JSON.stringify(datas));
    	              return;
    	          }
    			  layer.msg(datas.message, {icon: 2});
    			}
    	   	});
    	}
    	
    	var saveCode = function()
    	{
    		var name_param = $('#nameParam').val();
      	    var value_param = $('#value_param').val();
      	    var code_param = $('#code_param').val();
      	   var remarks = $('#remarks').val();
    		$.dpAjax({
    	   		url:'${basePath}/BaseSysParamsController/save',
    	   		data:{
    	   			"nameParam":name_param,
    	   			"valueParam":value_param,
    	   			"codeParam":code_param,
    	   			"remarks":remarks
    	   		},
    			success: function(datas)
    			{
    		 	  if(datas.flag == "100100")
    		 	  {
    		 		  layer.msg("添加成功", {icon: 6});
    		 		  $('#nameParam').val("");
    		      	  $('#value_param').val("");
    		      	  $('#code_param').val("");
    		      	 $('#remarks').val("");
    		 		  refresh();
    				  return;
    			  }
    			  if(datas.flag == "100200"){
    				  alert(JSON.stringify(datas));
    	              return;
    	          }
    			  layer.msg(datas.message, {icon: 2});
    			}
    	   	});
    	}
    	
    	var changelayer;
    	
    	var codeUpdate = function()
    	{	
    		var id = $('#id').val();
    		var name_param = $('#nameParamb').val();
      	    var value_param = $('#value_paramb').val();
      	    var code_param = $('#code_paramb').val();
      	    var remarks = $('#remarksb').val();
    		$.dpAjax({
    	   		url:'${basePath}/BaseSysParamsController/modify',
    	   		data:{
    	   			"id":id,
    	   			"nameParam":name_param,
    	   			"valueParam":value_param,
    	   			"codeParam":code_param,
    	   			"remarks":remarks
    	   		},
    			success: function(datas)
    			{
    		 	  if(datas.flag == "100100")
    		 	  {
    		 		  layer.msg("执行修改成功！", {icon: 6});
    		 		  layer.close(changelayer);
    		 		  refresh();
    				  return;
    			  }
    			  if(datas.flag == "100200"){
    				  alert(JSON.stringify(datas));
    	              return;
    	          }
    			  layer.msg(datas.message, {icon: 2});
    			}
    	   	});
    	}
    	
    </script>
</body>
</html>
